import React from 'react';
import { renderNumber } from '@/utils/common';
import { format } from '@/utils/datetime';
import CommonPage from '@/components/page/CommonPage';
const daoName = 'Gmcpdj';
const importName = 'Gmcpdj';
const columns: API.Column[] = [
  {
    title: '客户号',
    width: 110,
    sorter: true,
    dataIndex: 'CUID',
    key: 'CUID',
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '购买日期',
    width: 110,
    sorter: true,
    key: 'GMRQ',
    dataIndex: 'GMRQ',
    render: (data: any) => format(data, 'yyyy-MM-dd'),
    dispaly: true,
    filter: true,
    canEdit: true,
    export: true,
  },
  {
    title: '产品名称',
    width: 110,
    sorter: true,
    key: 'CPLX',
    dataIndex: 'CPNM',
    dispaly: true,
    filter: true,
    export: true,
  },
  {
    title: '购买金额(元)',
    width: 110,
    className: 'column-money',
    sorter: true,
    dataIndex: 'GMJR',
    render: (data) => renderNumber('.2f', data),
    key: 'GMJR',
    dispaly: true,
    align: 'right',
    filter: true,
    export: true,
  },
];

const controlsImport: API.Control[] = [
  { name: 'CUID', type: 'number', label: '客户号', grid: 12 / 24 },
  {
    name: 'CPLX',
    label: '产品名称',
    type: 'tree-select',
    grid: 12 / 24,
    rules: [{ required: true, message: '产品名称不能为空' }],
    dataType: 'number',
    fetch: { tableName: 'GmcpdjParam', optionTpl: 'CPNM', valueTpl: 'CPID', isDao: true },
  },
  {
    name: 'GMJR',
    label: '购买金额(元)',
    rules: [{ required: false, message: '不能为空' }],
    type: 'number',
    dataType: 'number',
    grid: 12 / 24,
  },
  { name: 'GMRQ', dataType: 'date', type: 'date', label: '购买日期', grid: 12 / 24 },
];

const controls: API.Control[] = [
  { name: 'CUID', type: 'number', label: '客户号', grid: 12 / 24 },
  {
    name: 'CPLX',
    label: '产品名称',
    type: 'tree-select',
    grid: 12 / 24,
    rules: [{ required: true, message: '产品名称不能为空' }],
    dataType: 'number',
    fetch: { tableName: 'GmcpdjParam', optionTpl: 'CPNM', valueTpl: 'CPID', isDao: true },
  },
  {
    name: 'GMJR',
    label: '购买金额(元)',
    rules: [{ required: false, message: '不能为空' }],
    type: 'number',
    dataType: 'number',
    grid: 12 / 24,
  },
  { name: 'GMRQ', dataType: 'date', type: 'date', label: '购买日期', grid: 12 / 24 },
];

const Gmcpdj: React.FC = () => {
  return (
    <CommonPage
      daoName={daoName}
      columns={columns}
      controls={controls}
      title="客户购买产品登记"
      importName={importName}
      importControls={controlsImport}
      importParamNames={['CPLX']}
      importMode="DeleteAfterInsert"
      importTemplateName="客户购买产品登记导入模板"
      initSorter={{ FieldName: 'GMRQ', Direction: 'DESC' }}
      keyColName="JLID"
    />
  );
};
export default Gmcpdj;
